# coding=utf-8
from ..common import mcEnum
from ..server import compFactory, levelId

_gameComp = compFactory.CreateGame(levelId)


class Ability(object):

    @staticmethod
    def isVisitor(player):
        """
        判断玩家是否为访客权限。
        :param str player: 玩家
        :rtype: bool
        """
        return compFactory.CreatePlayer(player).GetPlayerOperation() == 0

    @staticmethod
    def isMember(player):
        """
        判断玩家是否为成员权限。
        :param str player: 玩家
        :rtype: bool
        """
        return compFactory.CreatePlayer(player).GetPlayerOperation() == 1

    @staticmethod
    def isOperator(player):
        """
        判断玩家是否为管理员权限。
        :param str player: 玩家
        :rtype: bool
        """
        return compFactory.CreatePlayer(player).GetPlayerOperation() == 2

    @staticmethod
    def isCustom(player):
        """
        判断玩家是否为自定义权限。
        :param str player: 玩家
        :rtype: bool
        """
        return compFactory.CreatePlayer(player).GetPlayerOperation() == 3

    @staticmethod
    def canPlaceBlock(player):
        """
        获取玩家是否可以放置方块。
        创造模式时，拥有build权限或op权限即可放置方块。
        其它模式时，拥有build权限即可放置方块。
        :param str player: 玩家
        :rtype: bool
        """
        abilities = compFactory.CreatePlayer(player).GetPlayerAbilities()
        if _gameComp.GetPlayerGameType(player) == mcEnum.GameType.Creative:
            return abilities['build'] or abilities['op']
        return abilities['build']

    @staticmethod
    def canBreakBlock(player):
        """
        获取玩家是否可以破坏方块。
        创造模式时，拥有mine权限或op权限即可破坏方块。
        生存模式时，拥有mine权限即可破坏方块。
        :param str player: 玩家
        :rtype: bool
        """
        abilities = compFactory.CreatePlayer(player).GetPlayerAbilities()
        if _gameComp.GetPlayerGameType(player) == mcEnum.GameType.Creative:
            return abilities['mine'] or abilities['op']
        return abilities['mine']

    @staticmethod
    def canUseDoorsAndSwitches(player):
        """
        获取玩家是否可以使用门和开关，即与方块交互后能否改变方块状态或方块实体。
        该权限同时影响玩家是否可以扔出物品。
        :param str player: 玩家
        :rtype: bool
        """
        abilities = compFactory.CreatePlayer(player).GetPlayerAbilities()
        return abilities['doorsandswitches']

    @staticmethod
    def canOpenContainers(player):
        """
        获取玩家是否可以打开容器，即与方块交互后能否打开额外UI界面。
        :param str player: 玩家
        :rtype: bool
        """
        abilities = compFactory.CreatePlayer(player).GetPlayerAbilities()
        return abilities['opencontainers']

    @staticmethod
    def canAttackPlayers(player):
        """
        获取玩家是否可以攻击其他玩家。
        :param str player: 玩家
        :rtype: bool
        """
        abilities = compFactory.CreatePlayer(player).GetPlayerAbilities()
        return abilities['attackplayers']

    @staticmethod
    def canAttackMobs(player):
        """
        获取玩家是否可以攻击其它生物。
        :param str player: 玩家
        :rtype: bool
        """
        abilities = compFactory.CreatePlayer(player).GetPlayerAbilities()
        return abilities['attackmobs']

    @staticmethod
    def canUseOpCommand(player):
        """
        获取玩家是否可以使用操作员命令。
        :param str player: 玩家
        :rtype: bool
        """
        abilities = compFactory.CreatePlayer(player).GetPlayerAbilities()
        return abilities['op']

    @staticmethod
    def canUseTpCommand(player):
        """
        获取玩家是否可以使用传送命令。
        任意模式时，拥有teleport权限和op权限时才可使用传送命令。
        :param str player: 玩家
        :rtype: bool
        """
        abilities = compFactory.CreatePlayer(player).GetPlayerAbilities()
        return abilities['op'] and abilities['teleport']
